package serverClientLib;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Server extends Thread {
    private int port;
    private ServerSocket newSocket;
    
    public void setPort (int newPort) {
        port = newPort;
    }
    
    public void addSocket () {
        newSocket = null;
        
        try {
            newSocket = new ServerSocket (port);
            newSocket.setSoTimeout(15000);
        } catch (IOException ex) {
            System.err.println ("[Server] Error 0x00: Couldn't connect to socket " + port + ".");
        }
        
        System.out.println ("[Server] Port [" + port + "] succesfully installed.");
    }
    
    public void connectToSocket() {
        try {
            Socket channel = newSocket.accept();
        } catch (IOException ex) {
            System.err.println ("[Server] Error 0x00: Couldn't connect to socket " + port + ".");
        }
        
        System.out.println ("[Server] Port [" + port + "] succesfully installed.");
    }
    
    
    public void run() {
        setPort (8000);
        
        while (true) {
            addSocket();
            connectToSocket();
        }
    }

    public static void main (String[] args) {
        Thread t = new Server();
        t.start();
    }
}
